package cn.wolfcode.luowowo.article.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Strategy;
import cn.wolfcode.luowowo.article.service.IDestinatonService;
import cn.wolfcode.luowowo.article.service.IStrategyService;
import cn.wolfcode.luowowo.common.query.StrategyQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategy")
public class StrategyController {
    @Reference
    private IStrategyService strategyService;
    @Reference
    private IDestinatonService destinatonService;
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") StrategyQueryObject qo){
        //查询列表
        PageInfo pageInfo = strategyService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "strategy/list";
    }

    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep){
        //查询所有的目的地,传回给页面
        List<Destination> list = destinatonService.selectAllDest(deep);
        return list;
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Strategy strategy){
        //添加或者保存
        strategyService.saveOrUpdate(strategy);
        return new AjaxResult();
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        //添加或者保存
        strategyService.deleteById(id);
        return new AjaxResult();
    }

}
